﻿using System;
using System.Collections.Generic;
using System.Linq;
using Visifire.Charts;
using Visifire.Commons;
using SalePoints.WcfServices;


namespace SalePoints.Models
{
	public partial class SalePoint
	{
		
		public static void LoadData(DataLegendGroup legendGroup,SaleChannel channels,Action<List<SalePointInfo>> okCallback) {
			WcfServices.SalePointServicesClient proxy = new SalePoints.WcfServices.SalePointServicesClient();
			proxy.LoadDataCompleted += (sd, e) => {
				proxy.CloseAsync();
				if (e.Error != null) {
					LogServices.AddLog(e.Error, null);
					return;
				};
				if (okCallback != null) {
					try
					{
						okCallback(e.Result.ToList());
					}
					catch (Exception ex) {
						LogServices.AddLog(ex, null);
					}
				};
				
			};
			proxy.LoadDataAsync(resolveDataLegendGroup(legendGroup),resolveSaleChannel(channels));
		}
		private static WcfServices.DataLegendGroup resolveDataLegendGroup(DataLegendGroup group){
			return (SalePoints.WcfServices.DataLegendGroup)group;
		}
		private static WcfServices.SaleChannel resolveSaleChannel(SaleChannel channel) {
			return (SalePoints.WcfServices.SaleChannel)channel;
		}
	}
}
